using System;
using System.Collections.Generic;
using System.Text;
using ORMapping;
using NHibernate;

namespace DAL
{
    public class CardDAL
    {
        private EntityControl<Card> control;

        public CardDAL()
        {
            control = EntityControl<Card>.CreateEntityControl("ORMapping");
        }

        public Int32 AddCard(Card card)
        {
            return Convert.ToInt32(control.AddEntity(card));
        }

        public long CardCount()
        {
            return control.Count();
        }

        public IList<Card> GetAllCards(string strHQL, System.Collections.Generic.List<HQLParameter> hp)
        {
            return control.GetEntities(strHQL, hp);
        }

        public void UpdateCard(Card card)
        {
            control.UpdateEntity(card, card.CardID);
        }

        public Card GetCardByNO(String CardNO)
        {
            string strHQL = "from Card c where c.CardNO = :CardNO";
            System.Collections.Generic.List<HQLParameter> hp = new System.Collections.Generic.List<HQLParameter>(1);
            hp.Add(new HQLParameter(EnumHQLParameterType.STRING, "CardNO", CardNO));
            IList<Card> lc = control.GetEntities(strHQL, hp);
            return lc.Count > 0 ? lc[0]:null;
        }

    }
}
